<template>
	<view class="wrapper">
		<head-title titleText="设置" showLeftButton="true"></head-title>
		<view class="list flex_row">
			<text>对方查看我的手机/微信号需要开通VIP</text>
			<switch :checked="msg.is_allow_wx==1" @change="bindSwich1" />
		</view>
		<view class="list flex_row">
			<text>允许陌生人对我打招呼</text>
			<switch :checked="msg.is_mo_say_hello==1" @change="bindSwich2" />
		</view>
		<view class="list flex_row">
			<text>我的邀约活动只允许带礼物报名</text>
			<switch :checked="msg.is_gift_join==1" @change="bindSwich3" />
		</view>
		<view class="list flex_row">
			<text>进入我的用户主页需要鲜花解锁</text>
			<switch :checked="msg.is_see_flower==1" @change="bindSwich4" />
		</view>
	</view>
</template>
<script>
	import headTitle from "../../components/headTitle.vue";
	import common from "../../common/network.js";
	var session = '';
	export default {
		components:{headTitle},
		data(){
			return{
				msg:'',
			}
		},
		onLoad:function(options){
			if(options.session!=undefined){
				session = options.session;
				this.getMsg();
			}
		},
		onUnload:function(){
			this.keepMsg();
		},
		methods:{
			bindSwich1:function(res){
				var str = res.detail.value;
				if(str){
					this.msg.is_allow_wx = 1;
				}else{
					this.msg.is_allow_wx = 2;
				}
			},
			bindSwich2:function(res){
				var str = res.detail.value;
				if(str){
					this.msg.is_mo_say_hello = 1;
				}else{
					this.msg.is_mo_say_hello = 2;
				}
			},
			bindSwich3:function(res){
				var str = res.detail.value;
				if(str){
					this.msg.is_gift_join = 1;
				}else{
					this.msg.is_gift_join = 2;
				}
			},
			bindSwich4:function(res){
				var str = res.detail.value;
				if(str){
					this.msg.is_see_flower = 1;
				}else{
					this.msg.is_see_flower = 2;
				}
			},
			getMsg:function(){
				var that = this;
				var $data = {
					'type':'zset_index',
					'session':session
				};
				common.network.request($data,function(res){
					console.log(res)
					that.msg = res;
				})
			},
			keepMsg:function(){
				var that = this;
				var msg = that.msg;
				var $data = {
					'type':'zset_save_set',
					'session':session,
					'is_allow_wx': msg.is_allow_wx,	
					'is_mo_say_hello': msg.is_mo_say_hello,
					'is_gift_join': msg.is_gift_join,
					'is_see_flower': msg.is_see_flower,
				};
				common.network.request($data,function(res){
					console.log(res);
				})
			}
		}
	}
</script>

<style scoped>
	.wrapper{
		background: #F2F3F7;
		min-height: 100vh;
	}
	.list{
		justify-content: space-between;
		padding: 30px;
		margin-bottom: 1px;
		background: #fff;
	}
</style>
